/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package action.mail;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import myUtils.page.Result;
import org.apache.struts2.interceptor.ServletRequestAware;
import po.Mail;
import po.User;
import service.MailService;
import service.UserService;

/**
 *
 * @author sony
 */
public class SendBoxAction extends ActionSupport implements ServletRequestAware{

    MailService mailService;
    Result result;
    private HttpServletRequest request;
    UserService userService;

    @Override
    public String execute() {
        if (ActionContext.getContext().getSession().get("user") == null) {
            return ERROR;
        } else {
            User usr = (User) ActionContext.getContext().getSession().get("user");
            int page = request.getParameter("page") == null ? 1 : Integer.parseInt((String) request.getParameter("page"));

            result = mailService.getSendMails(usr.getId(),page);
            request.setAttribute("result", result);


            return SUCCESS;
        }
    }

    public MailService getMailService() {
        return mailService;
    }

    public void setMailService(MailService mailService) {
        this.mailService = mailService;
    }

    public void setServletRequest(HttpServletRequest arg0) {
       this.request = arg0;
    }

    public UserService getUserService() {
        return userService;
    }

    public void setUserService(UserService userService) {
        this.userService = userService;
    }

}
